<!-- 缺陷处理组件 -->
<template>
	<div>
		<el-dialog   :visible.sync="dialogVisible" width="70%" @close="SaveForm={}">
			<el-descriptions  title="缺陷处理表" direction="vertical" :column="4" border >
				<el-descriptions-item label="项目">{{defect.projectName}}</el-descriptions-item>
				<el-descriptions-item label="缺陷名称">{{defect.issueName}}</el-descriptions-item>
				<el-descriptions-item label="缺陷分类" >{{Type(defect.issueType)}}</el-descriptions-item>
				<el-descriptions-item label="缺陷状态" >{{State(defect.issueState)}}</el-descriptions-item>
				<el-descriptions-item label="严重程度" >{{severity(defect.issueSeverity)}}</el-descriptions-item>
				<el-descriptions-item label="优先级" >{{Priority(defect.issuePriority)}}</el-descriptions-item>
				<el-descriptions-item label="工时" >{{defect.actWorkHours}}</el-descriptions-item>
				<el-descriptions-item label="指派人" >{{defect.assignee}}</el-descriptions-item>
				<el-descriptions-item label="计划开始时间" >{{defect.planStartTime}}</el-descriptions-item>
				<el-descriptions-item label="计划完成时间" >{{defect.planEndTime}}</el-descriptions-item>
				<el-descriptions-item label="完成率" >{{doneRatio(defect.doneRatio)}}</el-descriptions-item>
				<el-descriptions-item label="缺陷描述" >{{defect.issueDesc}}</el-descriptions-item>
				<el-descriptions-item label="缺陷要求" >{{defect.doneCondition}}</el-descriptions-item>
			</el-descriptions>
			<!-- //加载评论 -->
			<el-table :data="comments" border style="width: 100%">
				<el-table-column stripe type="index" label="No." align="center">
				</el-table-column>
				<el-table-column stripe type="comment" label="反馈内容" align="center">
				</el-table-column>
				<el-table-column stripe type="createTime" label="反馈时间" align="center">
				</el-table-column>
			</el-table>
			<el-pagination layout="prev, pager, next" @current-change="loadPageC" :total="totalC"
				:page-size="pageQuery.size" :current-page="indexPage">
			</el-pagination>
			<!-- 附件列表 -->
			<div id="attachLoad">
				附件列表
				<el-link type="primary"  v-for="(item,index) in loadAttachs" @click="download(item.attachUrl)">
				{{index+1+"."}}   {{item.attachUrl}}  附件大小:{{item.fileSize/25}}kB
				</el-link>
				
			</div>
			<el-form :inline="true" v-model="pageQuery" class="demo-form-inline">
				<el-upload class="upload-demo" action="http://www.pawntest.com/attach/upload" :on-remove="handleRemove"
					list-type="picture" :on-success="successUp" :with-credentials="cookie" name="mf" :limit="limit"
					ref="files">
					<el-button size="small" type="primary">点击上传附件</el-button>
					<div slot="tip" class="el-upload__tip">只能上传单个文件</div>
				</el-upload>
				<el-form-item>
					<el-select v-model="SaveForm.issueState" placeholder="状态" clearable>
						<el-option v-for="item in stateDtos" v-if="item.stateCode!=1&&item.stateCode!=2" :label="item.stateDesc" :value="item.stateCode">
						</el-option>
					</el-select>
			</el-form-item>
			<el-form-item>
					<el-select v-model="SaveForm.doneRatio" placeholder="完成率" clearable>
						<el-option v-for="item in doneRatios"  :label="item+'%'" :value="item">
						</el-option>
					</el-select>
			</el-form-item>
			<el-form-item>
				<el-input v-model="SaveForm.actWorkHours" placeholder="耗时"></el-input>
			</el-form-item>
			<br>
			<el-form-item>
				<el-input type="textarea" v-model="SaveForm.logDesc" placeholder="处理描述"></el-input>
			</el-form-item>
			<el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="SaveForm.modifyTime" type="datetime"
				placeholder="选择处理时间" align="right">
			</el-date-picker>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible = false">取 消</el-button>
				<el-button type="primary" @click="save">确 定</el-button>
			</span>
		</el-dialog>
		<div>
			<el-form :inline="true" v-model="pageQuery" class="demo-form-inline">
				<el-form-item>
					<el-select v-model="pageQuery.projectId" placeholder="项目" clearable>
						<el-option v-for="item in projectDtos" :label="item.projectName" :value="item.projectId">
						</el-option>
					</el-select>
					<el-select v-model="pageQuery.issueState" placeholder="状态" clearable>
						<el-option v-for="item in stateDtos" :label="item.stateDesc" :value="item.stateCode">
						</el-option>
					</el-select>
					<el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="pageQuery.startTime" type="datetime"
						placeholder="选择开始时间" align="right">
					</el-date-picker>
					<el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="pageQuery.endTime" type="datetime"
						placeholder="选择结束时间" align="right">
					</el-date-picker>
					<el-form-item>
						<el-input v-model="pageQuery.keyword" placeholder="关键词搜索"></el-input>
					</el-form-item>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="query">查询</el-button>
				</el-form-item>
			</el-form>
		</div>
		<div id="defectList">
			<el-table :data="defects" border style="width: 100%">
				<el-table-column stripe type="index" label="No." align="center">
				</el-table-column>
				<el-table-column stripe prop="projectName" label="项目" align="center">
				</el-table-column>
				<el-table-column stripe prop="issueName" label="缺陷名称" align="center">
				</el-table-column>
				<el-table-column stripe prop="issueType" label="类型" align="center" :formatter="Types">
				</el-table-column>
				<el-table-column stripe prop="issuePriority" label="优先级" align="center" :formatter="Prioritys">
				</el-table-column>
				<el-table-column stripe prop="issueSeverity" label="严重度" align="center" :formatter="severitys">
				</el-table-column>
				<el-table-column stripe prop="issueState" label="状态" align="center" :formatter="States">
				</el-table-column>
				<el-table-column stripe prop="assignee" label="指派人" align="center">
				</el-table-column>
				<el-table-column stripe prop="planEndTime" label="预计完成时间" align="center">
				</el-table-column>
				<el-table-column stripe prop="modifyTime" label="更新时间" align="center">
				</el-table-column>
				<el-table-column label="操作" align="center">
					<template slot-scope="scope">
						<el-button size="mini" type="primary" :disabled="scope.row.issueState==4" icon="el-icon-edit"
							@click="update(scope.row)">
							处理</el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination layout="prev, pager, next" @current-change="loadPage" :total="total"
				:page-size="pageQuery.size" :current-page="indexPage">
			</el-pagination>
		</div>
	</div>
</template>

<script>
	export default {
		name: 'defect-deal',
		data() {
			return {
				doneRatios:[],
				limit: 1,
				file: "",
				cookie: true,
				attach: {},
				attachs: {
					attachDesc: "",
					attachName: "",
					attachUrl: "",
					fileSize: 0,
					issueId: 0
				},
				issueId: "",
				priorities: [],
				severityDtos: [],
				stateDtos: [],
				typeDtos: [],
				defects: [],
				defect:{},
				projectDtos: [],
				commentPagequery:{
					current: 1,
					size: 3,
					issueId:null
				},
				pageQuery: {
					current: 1,
					size: 3,
					startTime: null,
					endTime: null,
					issueState: null,
					issueType: null,
					keyword: null,
					projectId: null,
					queryStatus: 2,
				},
				dialogVisible: false,
				total: null,
				totalC: null,
				indexPage: 1,
				indexPageC: 1,
				SaveForm: {
					actWorkHours: null,
					doneRatio: null,
					issueId: null,
					issueState: null,
					logDesc: null,
					modifyTime: null
				},
				comments:[],
				loadAttachs:[],
			}
		},
		methods: {
			save() {
				this.attachs.attachName = this.attach.attachName,
				this.attachs.attachUrl = this.attach.attachUrl,
				this.attachs.fileSize = this.attach.fileSize,
				console.log(this.SaveForm)
				console.log(this.attachs)
				this.$http.post("/defectInfo/deal", this.SaveForm).then(resp => {
					if (resp.data.statusCode == 200) {
						this.attachs.issueId = resp.data.data.issueId
						if (this.attachs!='undfined'||this.attachs.attachUrl != null || this.attachs.attachUrl != "") {
							this.$http.post("/attach/save", this.attachs).then(resp => {
								if (resp.data.statusCode == 200) {
									this.SaveForm={}
									this.$refs.files.clearFiles()
									this.dialogVisible = false
								}
							})
						}

					}
				})
			},
			query() {
				this.loadDefect()
				this.pageQuery = {
					current: 1,
					size: 3,
					startTime: null,
					endTime: null,
					issueState: null,
					issueType: null,
					keyword: null,
					projectId: null,
					queryStatus: 2,
				}
			},
			loadDefect() {
				console.log(this.pageQuery)
				this.$http.post("/defectInfo/pageQuery", this.pageQuery).then(resp => {
					if (resp.data.statusCode == 200) {
						var data = resp.data.data
						this.defects = data.pageDto.data
						this.total = data.pageDto.total
						this.priorities = data.priorities
						this.severityDtos = data.severityDtos
						this.stateDtos = data.stateDtos
						this.typeDtos = data.typeDtos
						this.projectDtos = data.projectDtos
						console.log(this.defects)
					}
				})
			},
			//加载反馈列表
			loadComment(row){
				this.commentPagequery.issueId=row.issueId
				console.log(row.issueId)
				this.$http.post("/comment/load", this.commentPagequery).then(resp => {
					if (resp.data.flag) {
						this.comments = resp.data.data.data
						this.totalC=resp.data.data.total
						console.log(this.comments )
					}
				})
			},
			// 加载附件列表
			loadAttach(row){
				this.$http.post("/attach/load/"+ row.issueId).then(resp => {
					if (resp.data.flag) {
						this.loadAttachs = resp.data.data
						console.log(this.loadAttachs)
					}
				})
			},
			update(row) {
				this.loadAttach(row)//加载附件列表
				this.loadComment(row)//加载反馈列表
				this.dialogVisible = true//弹出框
				this.doneRatios=[],//完成率清零
				this.defect=row
				//完成率初始化
				var ratio=row.doneRatio
				for(var i=1;i<=(100-ratio)/10;i++){
					this.doneRatios.push(ratio+i*10)
				}
				this.SaveForm.issueId=row.issueId
				this.attachs.issueId=row.issueId
			},
			download(url){
				this.attachs.attachUrl=url;
				this.$confirm('是否下载?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http.post("/attach/download", this.attachs).then(resp => {
						if (resp.data.statusCode == 200) {
						}
					})
				}).catch(() => {
				});
			},
			//完成率
			doneRatio(ratio){
				return ratio+"%"
			},
			loadPage(index) {
				this.pageQuery.current = index,
					this.loadDefect();
			},
			loadPageC(indexC) {
				this.commentPagequery.current = index,
					this.loadComment()();
			},
			severity( cellValue) {
				var severity = this.severityDtos
				for (var i in severity) {
					if (cellValue == severity[i].severityCode) {
						return severity[i].severityDesc
					}
				}
			},
			Priority(cellValue) {
				var priorities = this.priorities
				for (var i in priorities) {
					if (cellValue == priorities[i].priorityCode) {
						return priorities[i].priorityDesc
					}
				}
			},
			State(cellValue) {
				var stateDtos = this.stateDtos
				for (var i in stateDtos) {
					if (cellValue == stateDtos[i].stateCode) {
						return stateDtos[i].stateDesc
					}
				}
			},
			Type (cellValue) {
				var typeDtos = this.typeDtos
				for (var i in typeDtos) {
					if (cellValue == typeDtos[i].typeCode) {
						return typeDtos[i].typeDesc
					}
				}
			},
			//表格初始化
			severitys( row, column, cellValue) {
				var severity = this.severityDtos
				for (var i in severity) {
					if (cellValue == severity[i].severityCode) {
						return severity[i].severityDesc
					}
				}
			},
			Prioritys(row, column,cellValue) {
				var priorities = this.priorities
				for (var i in priorities) {
					if (cellValue == priorities[i].priorityCode) {
						return priorities[i].priorityDesc
					}
				}
			},
			States(row, column, cellValue) {
				var stateDtos = this.stateDtos
				for (var i in stateDtos) {
					if (cellValue == stateDtos[i].stateCode) {
						return stateDtos[i].stateDesc
					}
				}
			},
			Types (row, column,cellValue) {
				var typeDtos = this.typeDtos
				for (var i in typeDtos) {
					if (cellValue == typeDtos[i].typeCode) {
						return typeDtos[i].typeDesc
					}
				}
			},
			successUp(resp, file, fileList) {
				// this.fileList = resp.data,
				this.attach = resp.data
				console.log(this.attach)
			},
			handleRemove(file, fileList) {
				console.log(file)
				this.attach = {};
				this.attach.attachUrl = file.response.data.attachUrl
				this.$http.post("/attach/remove", this.attach).then(resp => {
					if (resp.data.statusCode == 200) {}
				})
			},
		},
		created() {
			this.loadDefect()
			
		}

	}
</script>
<style>
#attachLoad{
	height: 100px;
	border: black solid;
	overflow-y: scroll;
}
</style>
